package eraserhead.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * Class for a line in the {@link Decision} Lines Event
 * @author Quanquan
 */
public class Line {
	/** The choice above this line */
	String choice = "";
	
	/** The position of this line (start at 0) */
	int position;
	
	/** The edges attached to this line in an ordered list*/
	public List<Edge> edges = new ArrayList<Edge>();
	
	/**
	 * Creates new {@link Line}
	 * @param n Position of the line
	 */
	public Line(int n) {
		this.position = n;
	}
	
	/**
	 * Returns the next edge by height.
	 * @param n Pixel height to get edges after
	 * @return Next {@link Edge} with a height greater than n
	 */
	public Edge nextEdge(int n) {
		Edge next = null;
		for (Edge e: edges)
			if (e.height > n) {
				if (next == null)
					next = e;
				else if (e.height < next.height && e.height > n)
					next = e;
			}
		return next;
	}

	
	/**
	 * Set the choice of this line
	 * @param choice New choice to set
	 */
	public void setChoice(String choice) {
		this.choice = choice;
	}
	
	/**
	 * Get the choice of this line
	 * @return {@link Line}'s choice 
	 */
	public String getChoice() {
		return this.choice;
	}
	
	/**
	 * Get the position of this line
	 * @return {@link Line}'s position, 0 based
	 */
	public int getPosition() {
		return this.position;
	}
	
	@Override
	public boolean equals(Object other) {
	    if (other == null) {
	    	return false;
	    }
	    if (other == this) {
	    	return true;
	    }
	    if (!(other instanceof Line)) {
	    	return false;
	    }
	    Line otherLine = (Line) other;
	    return otherLine.getPosition() == position;
	}
}